package com.fr.lintcode;

import java.util.ArrayList;
import java.util.List;

public class Q480 {

    /**
     * @param root: the root of the binary tree
     * @return: all root-to-leaf paths
     */
    public List<String> binaryTreePaths(TreeNode root) {
        // write your code here
    	List<String> rs = new ArrayList<>();
    	if(root == null) {
    		return rs;
    	}
    	String s = "";
    	binaryTreePaths(root, s, rs);
    	return rs;
    	
    }
    
    private void binaryTreePaths(TreeNode node , String path, List<String> rs) {
    	if(path.length() == 0) {
    		path += node.val;
    	}else {
    		path = path + "->" + node.val;
    	}
    	if(node.left == null && node.right == null) {
    		rs.add(path);
    		return;
    	}
    	if(node.left != null) {
    		binaryTreePaths(node.left, path, rs);
    	}
    	if(node.right != null) {
    		binaryTreePaths(node.right, path, rs);
    	}
    	
    }

}
